package com.framework.buss.bridge.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.framework.buss.bridge.model.ImageData;
import com.framework.buss.bridge.service.IImageDataService;
import com.framework.common.domain.ResultData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;

/**
 * @Description: 图片格式列表数据录入
 * @Author: jeecg-boot
 * @Date:   2023-05-18
 * @Version: V1.0
 */
@Api(tags="图片格式列表数据录入")
@RestController
@RequestMapping("/bridgeImageData")
@Slf4j
public class ImageDataController {
	@Autowired
	private IImageDataService imageDataService;
	
	/**
	 * 分页列表查询
	 *
	 * @param imageData
	 * @param pageNo
	 * @param pageSize
	 * @param req
	 * @return
	 */
	//@AutoLog(value = "图片格式列表数据录入-分页列表查询")
	@ApiOperation(value="图片格式列表数据录入-分页列表查询", notes="图片格式列表数据录入-分页列表查询")
	@GetMapping(value = "/list")
	public ResultData<IPage<ImageData>> queryPageList(ImageData imageData,
												  @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
												  @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
												  HttpServletRequest req) {
		LambdaQueryWrapper<ImageData> queryWrapper = new LambdaQueryWrapper();
		queryWrapper.eq(ImageData::getBridgeId, imageData.getBridgeId());
		Page<ImageData> page = new Page<ImageData>(pageNo, pageSize);
		IPage<ImageData> pageList = imageDataService.page(page, queryWrapper);
		return ResultData.data(pageList);
	}
	
	/**
	 *   添加
	 *
	 * @param imageData
	 * @return
	 */
	@ApiOperation(value="图片格式列表数据录入-添加", notes="图片格式列表数据录入-添加")
	//@RequiresPermissions("org.jeecg.biz.bridge:buss_image_data:add")
	@PostMapping(value = "/add")
	public ResultData<String> add(@RequestBody ImageData imageData) {
		imageDataService.save(imageData);
		return ResultData.success("添加成功！");
	}
	
	/**
	 *  编辑
	 *
	 * @param imageData
	 * @return
	 */
	@ApiOperation(value="图片格式列表数据录入-编辑", notes="图片格式列表数据录入-编辑")
	//@RequiresPermissions("org.jeecg.biz.bridge:buss_image_data:edit")
	@RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
	public ResultData<String> edit(@RequestBody ImageData imageData) {
		imageDataService.updateById(imageData);
		return ResultData.success("编辑成功!");
	}
	
	/**
	 *   通过id删除
	 *
	 * @param id
	 * @return
	 */
	@ApiOperation(value="图片格式列表数据录入-通过id删除", notes="图片格式列表数据录入-通过id删除")
	@DeleteMapping(value = "/delete")
	public ResultData<String> delete(@RequestParam(name="id",required=true) String id) {
		imageDataService.removeById(id);
		return ResultData.success("删除成功!");
	}
	
	/**
	 *  批量删除
	 *
	 * @param ids
	 * @return
	 */
	@ApiOperation(value="图片格式列表数据录入-批量删除", notes="图片格式列表数据录入-批量删除")
	//@RequiresPermissions("org.jeecg.biz.bridge:buss_image_data:deleteBatch")
	@DeleteMapping(value = "/deleteBatch")
	public ResultData<String> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
		this.imageDataService.removeByIds(Arrays.asList(ids.split(",")));
		return ResultData.success("批量删除成功!");
	}
	
	/**
	 * 通过id查询
	 *
	 * @param id
	 * @return
	 */
	//@AutoLog(value = "图片格式列表数据录入-通过id查询")
	@ApiOperation(value="图片格式列表数据录入-通过id查询", notes="图片格式列表数据录入-通过id查询")
	@GetMapping(value = "/queryById")
	public ResultData<ImageData> queryById(@RequestParam(name="id",required=true) String id) {
		ImageData imageData = imageDataService.getById(id);
		if(imageData==null) {
			return ResultData.error("未找到对应数据");
		}
		return ResultData.data(imageData);
	}

}
